﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using OOLib;

namespace NewTextDoc
{
   class Program
   {
      static void Main(string[] args)
      {
         // instanciate the ServiceManager
         // the ServiceManager is a singleton and can be created only once
         // use ServiceManager.Instance to access it
         var serviceManager = new ServiceManager();

         // create the Desktop
         var desktop = serviceManager.CreateDesktop();

         // use the utility function to create a new text document
         var textDoc = desktop.CreateTextDocument();

         // set the content of the document
         textDoc.Text.String = "Hello World";

         // save the document to a file
         var path = Path.Combine(Path.GetDirectoryName(typeof(Program).Assembly.Location), "HelloWorld.odt");
         textDoc.StoreAsFileName(path);

         // read the document string back and write it to console
         Console.WriteLine("Document string: {0}", textDoc.Text.String);

         // print the Document Url to the console
         Console.WriteLine("Document Url: {0}", textDoc.Url);

         // wait for input
         Console.WriteLine("Press key to continue ...");
         Console.ReadKey();

         // close the Desktop
         desktop.Terminate();

         // cleanup
         textDoc = null;
         desktop = null;
         serviceManager = null;
      }
   }
}
